/**
 * 
 */
package com.worksmap.core.action;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.worksmap.core.entity.User;
import com.worksmap.core.test.TestGeneralDao;

/**
 * 访问项目主页index.jsp
 * 用户主页不必登录即可查看
 * @author jack l12
 * 2013.7.5
 */
@Controller
public class IndexController extends BaseController {
	
	@Autowired
	TestGeneralDao testGeneralDao;
	
	/**
	 * 根据项目名称访问http://127.0.0.1/springMvc3/  
	 * 初始页面默认到项目主页
	 * jack
	 * 2013-7-5
	 */
	@RequestMapping(value = "/springMvc3", method = RequestMethod.GET)
	public String springMvc3(){
		logger.info("站点根目录访问跳转到勇哥的主页.");
		return getIndex();
	}
	
	/**
	 * 访问http://127.0.0.1/   
	 * 初始页面默认到项目主页
	 * jack
	 * 2013-7-5
	 */
	@RequestMapping(value = "", method = RequestMethod.GET)
	public String index(HttpServletRequest request){
		logger.info("站点根目录访问跳转到我的主页.");
		System.err.println("sadfasfasfasdfasfasfasdfas");
		return getIndex();
	}
	
	private String getIndex(){
		return "user/index";
//		return "manage/login_system";
	}
	
	@RequestMapping(value = "/testDao", method = RequestMethod.GET)
	public String testDao(){
		logger.info("站点根目录访问跳转到勇哥的主页.");
		List<User> userList = new ArrayList<User>();
		for(int i=0; i<5; i++){
			User user = new User();
			user.setPassWord("admins");
			user.setUserName("wang" + i);
			userList.add(user);
		}
		testGeneralDao.testBatchUpdate(userList);
		
//		User user = testGeneralDao.getUserById(22);
//		try {
//			user = testGeneralDao.test().get(0);
//		} catch (Exception e) {
//			e.printStackTrace();
//		}
		return "git/index";
	}
	
	@RequestMapping(value = "/git", method = RequestMethod.GET)
	public String index(){
		logger.info("站点根目录访问跳转到勇哥的主页.");
		testGeneralDao.updateTest();
		return "git/index";
	}
	
	@RequestMapping(value = "/html5", method = RequestMethod.GET)
	public String html5(){
		logger.info("html5测试模板，学习使用.");
		return "html5/index";
	}
	
	@RequestMapping(value = "/login", method = RequestMethod.GET)
	public String login(){
		logger.info("测试登录页面.");
		return "test/login";
	}

}
